/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.form.editor.gui.dialog.panel;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;

import javax.swing.JComboBox;
import javax.swing.JLabel;

import com.genia.toolbox.basics.editor.gui.dialog.panel.AbstractSettingsPanel;
import com.genia.toolbox.form.editor.gui.FormEditorGUI;
import com.genia.toolbox.form.editor.message.Messages;
import com.genia.toolbox.form.editor.model.bean.FormInitialSettings;
import com.genia.toolbox.form.editor.model.form.impl.FormType;

/**
 * The form selection panel. Used to create a form or to select a sub-form.
 */
@SuppressWarnings("serial")
public class TabSelectionPanel
    extends AbstractSettingsPanel<FormEditorGUI, FormInitialSettings>
{

  /**
   * The label of the tab type.
   */
  private JLabel labelTab = null;

  /**
   * The selection of the tab type.
   */
  private JComboBox comboTab = null;



  /**
   * Constructor.
   * 
   * @param gui
   *          The gui.
   */
  public TabSelectionPanel(FormEditorGUI gui)
  {
    super(gui);

    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    this.setLayout(layout);

    this.labelTab = new JLabel(this.getGui().getController().notifyTranslation(Messages.FORM_DIALOG_CREATION_TAB_TYPE));
    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(0, 0, 0, 0);
    this.add(this.labelTab, constraints);

    FormType[] typeTab = new FormType[2];
    typeTab[0] = FormType.VERTICAL;
    typeTab[1] = FormType.HORIZONTAL;
    this.comboTab = new JComboBox(typeTab);
    this.comboTab.addActionListener(this);
    constraints.gridx = 2;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(0, 5, 0, 0);
    this.add(this.comboTab, constraints);

  }



  /**
   * Get the settings from the current selection.
   * 
   * @return the settings.
   */
  @Override
  public FormInitialSettings getSettings()
  {
    FormInitialSettings settings = new FormInitialSettings();
    settings.setTabType((FormType) this.comboTab.getSelectedItem());
    return settings;
  }



  /**
   * Handle the action events.
   * 
   * @param e
   *          the action event.
   */
  public void actionPerformed(ActionEvent e)
  {
    // Do nothing
  }

}
